﻿using MiniExcelLibs;
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using 完工订单定时任务.http;

namespace 完工订单定时任务.报表
{
    public partial class FormPLC数据错误记录 : Form
    {
        public FormPLC数据错误记录()
        {
            InitializeComponent();
        }

        private void FormPLC数据错误记录_Load(object sender, EventArgs e)
        {
            dateTimePicker单据日期开始.Value = new DateTime(DateTime.Now.Year, DateTime.Now.Month, 1);
        }

        private void button查询_Click(object sender, EventArgs e)
        {
            string url = "http://115.231.66.30:23001/ViewReport/PLC数据错误记录";
            Dictionary<string, string> dic = new Dictionary<string, string>();
            dic.Add("单据日期开始", dateTimePicker单据日期开始.Value.ToString("yyyy-MM-dd"));
            dic.Add("单据日期结束", dateTimePicker单据日期结束.Value.AddDays(1).ToString("yyyy-MM-dd"));
            dic.Add("工单号", textBox工单号.Text);

            DataTable dt = HttpHelper.HttpPost<DataTable>(url, JsonConvert.SerializeObject(dic));
            dataGridView1.DataSource = dt;
            dataGridView1.Refresh();

        }

        private void button导出_Click(object sender, EventArgs e)
        {
            //导出excel
            if (dataGridView1.DataSource != null)
            {
                DataTable dt = (DataTable)dataGridView1.DataSource;
                string fileName = "PLC数据错误记录" + DateTime.Now.ToFileTime() + ".xlsx";
                SaveFileDialog saveFileDialog = new SaveFileDialog();
                saveFileDialog.Filter = "All files (*.*)|*.*";
                saveFileDialog.FileName = fileName;
                if (saveFileDialog.ShowDialog() == DialogResult.OK)
                {
                    MiniExcel.SaveAs(saveFileDialog.FileName, dt);
                    MessageBox.Show("导出成功");
                }

            }
            else
            {
                MessageBox.Show("没有数据");
            }
        }
    }
}
